#include "zbarrenderthread.h"
#include "qdebug.h"


void ZbarRenderThread::pushImage(QImage &image)
{
    // qDebug() << "ZbarRenderThread::pushImage(QImage image)";
    mutex.lock();
    m_image.swap(image);
    mutex.unlock();
    usleep(1000);
}

QImage ZbarRenderThread::getImage()
{
    return m_image;
}

void ZbarRenderThread::render()
{
    usleep(1000000/60);
    if(isPause) return;
    mutex.lock();
    QImage image=m_image.convertToFormat(QImage::Format_Grayscale8);
    mutex.unlock();
    QString decodeStr = mainzbar.DecoderInImg(image);
    if(!decodeStr.isEmpty()){
        // qDebug() << decodeStr;
        emit in_get_barcode_thread(decodeStr);
        pause();
        usleep(1000000/10);
    }else{
        // qDebug() << thread_image.size() << " 扫码中...";
    }
}
